<form method="post" action="{ADMINSCRIPT}?action=plugins&operation=config&do='.$pluginid.'&identifier=erling_kami_member&pmod=admin_config">
    <input type="hidden" name="formhash" value="{FORMHASH}" />
    <table class="tb tb2">
        <tr><th>配置名称</th><th>配置值</th><th>配置说明</th></tr>

        <!--{loop $configs $config}-->
        <!--{if !in_array($config['key'], ['position_float_value', 'position_float_color', 'position_float_bgcolor'])}-->
        <tr>
            <td>{$config['name']}</td>
            <td>
            <!--{if in_array($config['key'], ['user_group_days', 'kami_expire_time', 'kami_length'])}-->
                <input type="number" name="config[{$config['key']}]" value="{$config['value']}" min="1" />
                  <!--{if $config['key']=='kami_expire_time' || $config['key']=='user_group_days'}-->
                    <span>天</span>
                  <!--{/if}-->
            <!--{elseif $config['key'] == 'kami_char_type'}-->
                <!--{eval 
                    $char_types = json_decode($config['value'], true);
                    $char_type_labels = ['数字', '小写字母', '大写字母', '特殊字符'];
                }-->
                <!-- 循环遍历字符类型标签 -->
                <!--{loop $char_type_labels $index $label}-->
                    <label>
                        <input 
                            type="checkbox" 
                            name="config[{$config['key']}][]" 
                            value="1" 
                            <!--{if isset($char_types[$index]) && $char_types[$index] == '1'}-->checked<!--{/if}-->
                        />
                        {$label}
                    </label>
                <!--{/loop}-->
            <!--{elseif $config['key'] == 'kami_format'}-->
                <input 
                    type="text" 
                    name="config[{$config['key']}]" 
                    value="{$config['value']}" 
                    id="kami_format_input"
                    oninput="validateKamiFormat(this)"
                />
                <span id="kami_format_error" style="color: #ff5353; display: none;">输入内容不为空时必须包含 X</span>
            <!--{elseif $config['key'] == 'nav_position'}-->
                <select name="config[{$config['key']}]">
                    <option value="">-- 不显示 --</option>
                    <option value="global_cpnav_extra1" <!--{if $config['value'] == 'global_cpnav_extra1'}-->selected<!--{/if}-->>左上顶部</option>
                    <option value="global_usernav_extra3" <!--{if $config['value'] == 'global_usernav_extra3'}-->selected<!--{/if}-->>用户导航栏</option>
                    <option value="global_nav_extra" <!--{if $config['value'] == 'global_nav_extra'}-->selected<!--{/if}-->>主导航栏</option>
                </select>
            <!--{elseif $config['key'] == 'user_group'}-->
                <select name="config[{$config['key']}]">
                    
                    <!-- 自定义用户组 -->
                    <optgroup label="自定义用户组">
                        <!--{loop $special_groups $group}-->
                        <option value="{$group['groupid']}" <!--{if $config['value'] == $group['groupid']}-->selected<!--{/if}-->>{$group['grouptitle']}</option>
                        <!--{/loop}-->
                    </optgroup>
                </select>
            <!--{else}-->
                <input type="text" name="config[{$config['key']}]" value="{$config['value']}" />
            <!--{/if}-->
            </td>
            <td>{$config['desc']}</td>
        </tr>
        <!--{/if}-->
        <!--{/loop}-->

    </table>
    <input type="submit" class="btn" name="configsubmit" value="提交保存" />
</form>

<script>
    function validateKamiFormat(input) {
        const value = input.value;
        const errorSpan = document.getElementById('kami_format_error');
        if (errorSpan) {
            if (value !== '' && !value.includes('X')) {
                errorSpan.textContent = '输入内容不为空时必须包含 X';
                errorSpan.style.display = 'inline';
            } else {
                errorSpan.style.display = 'none';
            }
        }
    }

    // 表单提交时验证
    document.querySelector('form').addEventListener('submit', function(e) {
        const kamiFormatInput = document.getElementById('kami_format_input');
        const errorSpan = document.getElementById('kami_format_error');
        if (errorSpan && kamiFormatInput) {
            const value = kamiFormatInput.value;
            if (value !== '' && !value.includes('X')) {
                errorSpan.style.display = 'inline';
                e.preventDefault(); 
            }
        }
    });
</script>